package com.example.esaclient;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.app.Activity;
import android.content.SharedPreferences;



public class GlobalSettings {

	public static final String NAMESPACE = "http://tempuri.org/";
	public static final String SOAP_ACTION = "http://tempuri.org/IServiceRest/";
	
	public static final String PREF_ESA_URL = "esa_url";
	public static final String PREF_ESA_USRID = "esa_userID";
	static final String PREF_KEY_TWITTER_LOGIN = "isTwitterLogedIn";
	static final String PREF_KEY_GOOGLE_LOGIN = "isGoogleLogedIn";
	static final String PREF_KEY_FACEBOOK_LOGIN = "isFacebookLogedIn";
	static final String PREF_KEY_TWITTER_USERNAME = "key_tw_user";
	static final String PREF_KEY_FACEBOOK_USERNAME = "key_fb_user";
	static final String PREF_KEY_GOOGLE_USERNAME = "key_gp_user";
	static final String PREF_KEY_TWITTER_ID = "key_tw_id";
	static final String PREF_KEY_FACEBOOK_ID = "key_fb_id";
	static final String PREF_KEY_GOOGLE_ID= "key_gp_id";
	
	static final String PREF_TWITTER_TOKEN= "TW_token";
	static final String PREF_FACEBOOK_TOKEN= "FB_token";
	
	static final String PREF_KEY_LAST_SRV_UPDATE = "key_lastupdate";
	
	private static SharedPreferences mSharedPreferences;
	public Activity caller;
	
	public GlobalSettings(Activity callerActivity){
		caller=callerActivity;
	}
	
	public String getPrefString(String prefName){	
		mSharedPreferences =  caller.getSharedPreferences("MyPref", 0);		
		return mSharedPreferences.getString(prefName,"");		
	}
	
	public Boolean getPrefBool(String prefName){	
		mSharedPreferences =  caller.getSharedPreferences("MyPref", 0);		
		return mSharedPreferences.getBoolean(prefName,false);	
		}
	
	public int getPrefInt(String prefName){	
		mSharedPreferences =  caller.getSharedPreferences("MyPref", 0);		
		return mSharedPreferences.getInt(prefName,0);	
		}

	//utility method for conversion from InputStream to String
	public static String convertStreamToString(InputStream is) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        StringBuilder sb = new StringBuilder();
  
        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return sb.toString();
    }
}
